import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/views/layout/Layout'

export const constantRouterMap = [{
        path: '',
        component: Layout,
        redirect: 'index',
        children: [{
            path: 'index',
            component: () => import('@/views/index'),
            name: 'index',
            meta: {
                title: 'index',
                icon: 'index',
                noCache: true,
                affix: true
            }
        }]
    },
    {
        path: '/index',
        component: Layout,
        redirect: 'index',
        children: [{
            path: 'index',
            component: () => import('@/views/index'),
            name: 'index',
            meta: {
                title: 'index',
                icon: 'index',
                noCache: true,
                affix: true
            }
        }]
    },
    {
        path: '/tab',
        component: Layout,
        children: [{
            path: 'index',
            component: () => import('@/views/index'),
            name: 'Tab',
            meta: {
                title: 'tab',
                icon: 'tab'
            }
        }]
    },
    {
        path: '/product',
        component: Layout,
        redirect: '/product/index',
        children: [{
                path: 'index',
                component: () => import('@/views/product/index'),
                hidden: true,
                name: 'product'
            },
            {
                path: 'detail',
                component: () => import('@/views/product/detail'),
                hidden: true,
                name: '/product/detail'
            },
            {
                path: 'collect',
                component: () => import('@/views/product/collect'),
                hidden: true,
                name: 'collect'
            }
        ]
    },
    {
        path: '/aboutus',
        component: Layout,
        redirect: '/aboutus/index',
        children: [{
                path: 'index',
                component: () => import('@/views/aboutus/index'),
                hidden: true,
                name: 'aboutus'
            },
            {
                path: 'page',
                component: () => import('@/views/aboutus/page'),
                hidden: true,
                name: 'page'
            },
            {
                path: 'contact',
                component: () => import('@/views/aboutus/contact'),
                hidden: true,
                name: 'contact'
            }
        ]
    },
    {
        path: '/center',
        component: Layout,
        redirect: '/center/index',
        children: [{
                path: 'index',
                component: () => import('@/views/center/index'),
                hidden: true,
                name: 'center'
            },
            {
                path: 'order',
                component: () => import('@/views/center/order'),
                hidden: true,
                name: 'order'
            },
            {
                path: 'detail',
                component: () => import('@/views/center/order/detail'),
                hidden: true,
                name: 'orderDetail'
            },
            {
                path: 'integration',
                component: () => import('@/views/center/integration'),
                hidden: true,
                name: 'integration'
            },
            {
                path: 'mall',
                component: () => import('@/views/center/mall'),
                hidden: true,
                name: 'mall'
            },
            {
                path: 'coupon',
                component: () => import('@/views/center/coupon'),
                hidden: true,
                name: 'coupon'
            },
            {
                path: 'qrcode',
                component: () => import('@/views/center/qrcode'),
                hidden: true,
                name: 'qrcode'
            },
            {
                path: 'qrcodestore',
                component: () => import('@/views/center/qrcodestore'),
                hidden: true,
                name: 'qrcodestore'
            },
            {
                path: 'account',
                component: () => import('@/views/center/account'),
                hidden: true,
                name: 'account'
            },
            {
                path: 'store',
                component: () => import('@/views/center/account/store'),
                hidden: true,
                name: 'store'
            },
            {
                path: 'store_account',
                component: () => import('@/views/center/store_account'),
                hidden: true,
                name: 'store_account'
            },
            {
                path: 'addressIndex',
                component: () => import('@/views/center/account/addrs'),
                hidden: true,
                name: 'addressIndex'
            },
            {
                path: 'addressAdd',
                component: () => import('@/views/center/account/addradd'),
                hidden: true,
                name: 'addressAdd'
            },
            {
                path: 'addressModify',
                component: () => import('@/views/center/account/addrModify'),
                hidden: true,
                name: 'addressModify'
            },
            {
                path: 'sex',
                component: () => import('@/views/center/account/sex'),
                hidden: true,
                name: 'sex'
            },
            {
                path: 'birthday',
                component: () => import('@/views/center/account/birthday'),
                hidden: true,
                name: 'birthday'
            },
            {
                path: 'tel',
                component: () => import('@/views/center/account/tel'),
                hidden: true,
                name: 'tel'
            },
            {
                path: 'password',
                component: () => import('@/views/center/account/password'),
                hidden: true,
                name: 'password'
            },
            {
                path: 'sms',
                component: () => import('@/views/center/account/sms'),
                hidden: true,
                name: 'sms'
            },
            {
                path: 'shop',
                component: () => import('@/views/center/shop'),
                hidden: true,
                name: 'shop'
            },
            {
                path: 'commission',
                component: () => import('@/views/center/commission'),
                hidden: true,
                name: 'commission'
            },
            {
                path: 'fanli',
                component: () => import('@/views/center/fanli'),
                hidden: true,
                name: 'fanli'
            },
            {
                path: 'cash',
                component: () => import('@/views/center/cash'),
                hidden: true,
                name: 'cash'
            },
            {
                path: 'customer',
                component: () => import('@/views/center/customer'),
                hidden: true,
                name: 'customer'
            },
            {
                path: 'cashback',
                component: () => import('@/views/center/cashback'),
                hidden: true,
                name: 'cashback'
            },
            {
                path: 'clerk',
                component: () => import('@/views/center/clerk'),
                hidden: true,
                name: 'clerk'
            },
            {
                path: 'customerList',
                component: () => import('@/views/center/customerList'),
                hidden: true,
                name: 'customerList'
            },
            {
                path: 'saleman',
                component: () => import('@/views/center/saleman'),
                hidden: true,
                name: 'saleman'
            },
            {
                path: 'customerDetail',
                component: () => import('@/views/center/customerDetail'),
                hidden: true,
                name: 'customerDetail'
            },
            {
                path: 'withdraw',
                component: () => import('@/views/center/withdraw'),
                hidden: true,
                name: 'withdraw'
            }
        ],
        meta: {
            requireLogin: true // 当前路由需要校验，不需要就不用写
        }
    },
    {
        path: '/login',
        component: Layout,
        redirect: '/login/login',
        children: [{
                path: 'login',
                component: () => import('@/views/login/login'),
                hidden: true,
                name: 'login'
            }, {
                path: 'index',
                component: () => import('@/views/login/index'),
                hidden: true,
                name: 'index'
            },
            {
                path: 'forgetpw',
                component: () => import('@/views/login/forgetpw'),
                hidden: true,
                name: 'forgetpw'
            },
            {
                path: 'msgvalidate',
                component: () => import('@/views/login/msgvalidate'),
                hidden: true,
                name: 'msgvalidate'
            },
            {
                path: 'bindmobile',
                component: () => import('@/views/login/bindmobile'),
                hidden: true,
                name: 'bindmobile'
            },
            {
                path: 'storelogin',
                component: () => import('@/views/login/storelogin'),
                hidden: true,
                name: 'storelogin'
            },
            {
                path: 'agentlogin',
                component: () => import('@/views/login/agentlogin'),
                hidden: true,
                name: 'agentlogin'
            },
            {
                path: 'clerklogin',
                component: () => import('@/views/login/clerklogin'),
                hidden: true,
                name: 'clerklogin'
            },
            {
                path: 'centerlogin',
                component: () => import('@/views/login/centerlogin'),
                hidden: true,
                name: 'centerlogin'
            },
            {
                path: 'spreadlogin',
                component: () => import('@/views/login/spreadlogin'),
                hidden: true,
                name: 'spreadlogin'
            },
            {
                path: 'reset',
                component: () => import('@/views/login/reset'),
                hidden: true,
                name: 'reset'
            },
            {
                path: 'register_store',
                component: () => import('@/views/login/register_store'),
                hidden: true,
                name: 'register_store'
            }
        ]
    },
    {
        path: '/author',
        component: Layout,
        redirect: '/author/author',
        children: [{
            path: 'author',
            component: () => import('@/views/author/index'),
            hidden: true,
            name: 'author'
        }]
    },
    {
        path: '/auth-redirect',
        component: () => import('@/views/index'),
        hidden: true
    }
]

export default new Router({
    mode: 'history', // require service support
    scrollBehavior: () => ({
        y: 0
    }),
    routes: constantRouterMap
})

export const asyncRouterMap = [{
        path: '/permission',
        component: Layout,
        redirect: '/index',
        alwaysShow: true, // will always show the root menu
        meta: {
            title: 'permission',
            icon: 'lock',
            roles: ['admin', 'editor'] // you can set roles in root nav
        },
        children: [{
                path: 'page',
                component: () => import('@/views/index'),
                name: 'PagePermission',
                meta: {
                    title: 'pagePermission',
                    roles: ['admin'] // or you can only set roles in sub nav
                }
            },
            {
                path: 'directive',
                component: () => import('@/views/index'),
                name: 'DirectivePermission',
                meta: {
                    title: 'directivePermission'
                    // if do not set roles, means: this page does not require permission
                }
            }
        ]
    },
    {
        path: '/error-log',
        component: Layout,
        redirect: 'noredirect',
        children: [{
            path: 'log',
            component: () => import('@/views/index'),
            name: 'ErrorLog',
            meta: {
                title: 'errorLog',
                icon: 'bug'
            }
        }]
    },
    {
        path: '*',
        redirect: '/404',
        hidden: true
    }
]
